package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.AlertRuleDto;
import com.zzyl.service.AlertRuleService;
import com.zzyl.vo.AlertRuleVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/alert-rule")
@Api(tags = "告警规则")
public class AlertRuleController {

    @Autowired
    private AlertRuleService alertRuleService;

    @PostMapping("/create")
    @ApiOperation(value = "新增告警规则")
    public ResponseResult createAlertRule(@RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.createAlertRule(alertRuleDto);
        return ResponseResult.success();
    }

    @GetMapping("/get-page")
    @ApiOperation(value = "分页查询告警规则")
    public ResponseResult<PageResponse<AlertRuleVo>> getPage(Integer pageNum, Integer pageSize, String alertRuleName ,String functionId,String productKey) {
        PageResponse<AlertRuleVo> list = alertRuleService.getPage(pageNum, pageSize, alertRuleName, functionId, productKey);
        return ResponseResult.success(list);
    }

    @GetMapping("/read/{id}")
    @ApiOperation(value = "根据id查询告警规则")
    public ResponseResult<AlertRuleVo> read(@PathVariable Long id) {
        AlertRuleVo alertRuleVo = alertRuleService.read(id);
        return ResponseResult.success(alertRuleVo);
    }
    @PutMapping("/update/{id}")
    @ApiOperation(value = "更新告警规则")
    public ResponseResult update(@PathVariable Long id, @RequestBody AlertRuleDto alertRuleDto) {
        alertRuleService.update(id,alertRuleDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/delete/{id}")
    @ApiOperation(value = "根据id删除告警规则")
    public ResponseResult delete(@PathVariable Long id) {
        alertRuleService.delete(id);
        return ResponseResult.success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation(value = "启用-禁用")
    public ResponseResult updateStatus(@PathVariable Long id, @PathVariable Integer status) {
        alertRuleService.updateStatus(id, status);
        return ResponseResult.success();
    }
}
